
require(['./config'],()=>{
   require(['bootstrap','cookie','jquery','verify','footer'],()=>{
      class Login{
         constructor(){
            this.init()
            this.fn()
            
         }
         init(){
              var free=$('#free');
            this.$username=$('#exampleInputEmail1')
            this.$password=$('#exampleInputPassword1')
            this.$idcode=$('#incode')
               // console.log(username)
            $('#btn').on('click',()=>{
               var username=this.$username.val(),
                   password=this.$password.val(),
                   idcodeVal=this.$idcode.val();
              var userList =localStorage.getItem('userList')
              if(userList){
                 userList =JSON.parse(userList)
                 var  isExist =userList.some(userInfo=>{
                    return userInfo.username === username&&userInfo.password===password
                 })
                 if(isExist){
                    var userInfo={username,password}
                    if(free.checked){
                       $.cookie('userInfo',JSON.stringify(userInfo),{expires:7,path:'/'})
                    }else{
                       $.cookie('userInfo',JSON.stringify(userInfo),{path:'/'})
                    }
                    alert('登录成功，即将跳转页面')
                    window.open('/index.html')
                 }else{
                    alert('用户名或密码错误，请重试')
                 }
              }else{
                 alert('没有您的信息，请先注册，即将跳转至注册页面')
                 window.location.replace('/html/register.html')
              }
            })                            
         }
        fn(){
         $.idcode.setCode();

         $("#btns").click(function (){
				var IsBy = $.idcode.validateCode(); 
				alert(IsBy);
				console.log(IsBy);
          
			});
        }
      }
      new Login()
   })
})